home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / firmwaredialog.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  3.0 KB  |  109 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2008 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #  
  19. # Authors: Don Welch
  20. #
  21.  
  22. # Std Lib
  23. import operator
  24.  
  25. # Local
  26. from base.g import *
  27. from base import device, utils
  28. from prnt import cups
  29. from base.codes import *
  30. from ui_utils import *
  31.  
  32. # Qt
  33. from PyQt4.QtCore import *
  34. from PyQt4.QtGui import *
  35.  
  36. # Ui
  37. from firmwaredialog_base import Ui_Dialog
  38.  
  39.  
  40. class FirmwareDialog(QDialog, Ui_Dialog):
  41.     def __init__(self, parent, device_uri):
  42.         QDialog.__init__(self, parent)
  43.         self.setupUi(self)
  44.         self.device_uri = device_uri
  45.         self.initUi()
  46.         QTimer.singleShot(0, self.updateUi)
  47.  
  48.  
  49.     def initUi(self):
  50.         self.DeviceComboBox.setFilter({'fw-download' : (operator.gt, 0)})
  51.  
  52.         self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_noDevices"), self.DeviceUriComboBox_noDevices)
  53.         self.connect(self.DeviceComboBox, SIGNAL("DeviceUriComboBox_currentChanged"), self.DeviceUriComboBox_currentChanged)
  54.         self.connect(self.CancelButton, SIGNAL("clicked()"), self.close)
  55.         self.connect(self.DownloadFirmwareButton, SIGNAL("clicked()"), self.downloadFirmware)
  56.  
  57.         # Application icon
  58.         self.setWindowIcon(QIcon(load_pixmap('prog', '48x48')))
  59.  
  60.         if self.device_uri:
  61.             self.DeviceComboBox.setInitialDevice(self.device_uri)
  62.  
  63.  
  64.     def updateUi(self):
  65.         self.DeviceComboBox.updateUi()
  66.  
  67.  
  68.     def DeviceUriComboBox_currentChanged(self, device_uri):
  69.         self.device_uri = device_uri
  70.         # Update
  71.  
  72.  
  73.     def DeviceUriComboBox_noDevices(self):
  74.         FailureUI(self, self.__tr("<b>No devices that support firmware download found.</b>"))
  75.         self.close()
  76.  
  77.  
  78.     def downloadFirmware(self):
  79.         d = None
  80.  
  81.         try:    
  82.             try:
  83.                 d = device.Device(self.device_uri)
  84.             except Error:
  85.                 CheckDeviceUI(self)
  86.                 return
  87.  
  88.             try:
  89.                 d.open()
  90.             except Error:
  91.                 CheckDeviceUI(self)
  92.             else:
  93.                 if d.isIdleAndNoError():
  94.                     ok = d.downloadFirmware()
  95.  
  96.                 else:
  97.                     CheckDeviceUI(self)
  98.  
  99.         finally:
  100.             if d is not None:
  101.                 d.close()
  102.  
  103.         self.close()
  104.  
  105.  
  106.     def __tr(self,s,c = None):
  107.         return qApp.translate("FirmwareDialog",s,c)
  108.  
  109.